🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / ui / src / commonMain / kotlin / org / meshtastic / core / ui / component / PermissionRecoveryCard.kt
Displaying Raw • Download
core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/component/PermissionRecoveryCard.kt b8ab53e712871d076effd2defc55be720495aba5 (b8ab53e7) Text, 5.79 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ui.component
Tff7b72import T7ee787androidx.compose.foundation.layout.Arrangement
Tff7b72import T7ee787androidx.compose.foundation.layout.Column
Tff7b72import T7ee787androidx.compose.foundation.layout.Row
Tff7b72import T7ee787androidx.compose.foundation.layout.Spacer
Tff7b72import T7ee787androidx.compose.foundation.layout.fillMaxWidth
Tff7b72import T7ee787androidx.compose.foundation.layout.padding
Tff7b72import T7ee787androidx.compose.foundation.layout.width
Tff7b72import T7ee787androidx.compose.material3.Button
Tff7b72import T7ee787androidx.compose.material3.Icon
Tff7b72import T7ee787androidx.compose.material3.MaterialTheme
Tff7b72import T7ee787androidx.compose.material3.Surface
Tff7b72import T7ee787androidx.compose.material3.Text
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.ui.Alignment
Tff7b72import T7ee787androidx.compose.ui.Modifier
Tff7b72import T7ee787androidx.compose.ui.graphics.vector.ImageVector
Tff7b72import T7ee787androidx.compose.ui.unit.dp
Tff7b72import T7ee787org.jetbrains.compose.resources.stringResource
Tff7b72import T7ee787org.meshtastic.core.resources.Res
Tff7b72import T7ee787org.meshtastic.core.resources.grant_permission
Tff7b72import T7ee787org.meshtastic.core.resources.open_settings
Tff7b72import T7ee787org.meshtastic.core.ui.icon.AppSettingsAlt
Tff7b72import T7ee787org.meshtastic.core.ui.icon.ErrorOutline
Tff7b72import T7ee787org.meshtastic.core.ui.icon.MeshtasticIcons
Tff7b72import T7ee787org.meshtastic.core.ui.util.PermissionStatus
Tff7b72import T7ee787org.meshtastic.core.ui.util.PermissionUiState
T8b949e/**
* A reusable error-state card: an `errorContainer` message box plus one full-width recovery action. Generalizes the
* compass warning/recovery pattern so any feature can present context plus a single corrective action (request a
* permission, open Bluetooth/Wi-Fi/app settings, etc.).
*
* @param message the user-facing explanation of what is wrong.
* @param actionLabel the recovery button label.
* @param onAction invoked when the recovery button is tapped.
* @param actionIcon optional leading icon for the recovery button.
*/
Tf0883e@Composable
Tff7b72fun Td2a8ffRecoveryCardTb4b4b4(
Te6edf3messageTb4b4b4: Tffa657StringTb4b4b4,
Te6edf3actionLabelTb4b4b4: Tffa657StringTb4b4b4,
Te6edf3onActionTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4,
Te6edf3modifierTb4b4b4: Te6edf3Modifier Tff7b72= Te6edf3ModifierTb4b4b4,
Te6edf3actionIconTb4b4b4: Te6edf3ImageVector? Tff7b72= Tff7b72nullTb4b4b4,
Tb4b4b4) Tb4b4b4{
Te6edf3ColumnTb4b4b4(Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4.Te6edf3fillMaxWidthTb4b4b4(Tb4b4b4)Tb4b4b4, Te6edf3verticalArrangement Tff7b72= Te6edf3ArrangementTb4b4b4.Te6edf3spacedByTb4b4b4(T79c0ff8.Te6edf3dpTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3SurfaceTb4b4b4(
Te6edf3tonalElevation Tff7b72= T79c0ff2.Te6edf3dpTb4b4b4,
Te6edf3shape Tff7b72= Te6edf3MaterialThemeTb4b4b4.Te6edf3shapesTb4b4b4.Te6edf3mediumTb4b4b4,
Te6edf3color Tff7b72= Te6edf3MaterialThemeTb4b4b4.Te6edf3colorSchemeTb4b4b4.Te6edf3errorContainerTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3ModifierTb4b4b4.Te6edf3fillMaxWidthTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4) Tb4b4b4{
Te6edf3RowTb4b4b4(
Te6edf3modifier Tff7b72= Te6edf3ModifierTb4b4b4.Te6edf3paddingTb4b4b4(T79c0ff1T79c0ff2.Te6edf3dpTb4b4b4)Tb4b4b4,
Te6edf3verticalAlignment Tff7b72= Te6edf3AlignmentTb4b4b4.Te6edf3CenterVerticallyTb4b4b4,
Te6edf3horizontalArrangement Tff7b72= Te6edf3ArrangementTb4b4b4.Te6edf3spacedByTb4b4b4(T79c0ff1T79c0ff2.Te6edf3dpTb4b4b4)Tb4b4b4,
Tb4b4b4) Tb4b4b4{
Te6edf3IconTb4b4b4(
Te6edf3imageVector Tff7b72= Te6edf3MeshtasticIconsTb4b4b4.Te6edf3ErrorOutlineTb4b4b4,
Te6edf3contentDescription Tff7b72= Tff7b72nullTb4b4b4,
Te6edf3tint Tff7b72= Te6edf3MaterialThemeTb4b4b4.Te6edf3colorSchemeTb4b4b4.Te6edf3onErrorContainerTb4b4b4,
Tb4b4b4)
Te6edf3TextTb4b4b4(
Te6edf3text Tff7b72= Te6edf3messageTb4b4b4,
Te6edf3color Tff7b72= Te6edf3MaterialThemeTb4b4b4.Te6edf3colorSchemeTb4b4b4.Te6edf3onErrorContainerTb4b4b4,
Te6edf3style Tff7b72= Te6edf3MaterialThemeTb4b4b4.Te6edf3typographyTb4b4b4.Te6edf3bodyMediumTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Te6edf3ButtonTb4b4b4(Te6edf3onClick Tff7b72= Te6edf3onActionTb4b4b4, Te6edf3modifier Tff7b72= Te6edf3ModifierTb4b4b4.Te6edf3fillMaxWidthTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3actionIcon Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3IconTb4b4b4(Te6edf3imageVector Tff7b72= Te6edf3actionIconTb4b4b4, Te6edf3contentDescription Tff7b72= Tff7b72nullTb4b4b4)
Te6edf3SpacerTb4b4b4(Te6edf3modifier Tff7b72= Te6edf3ModifierTb4b4b4.Te6edf3widthTb4b4b4(T79c0ff8.Te6edf3dpTb4b4b4)Tb4b4b4)
Tb4b4b4}
Te6edf3TextTb4b4b4(Te6edf3text Tff7b72= Te6edf3actionLabelTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
T8b949e/**
* A [RecoveryCard] specialized for a missing runtime permission, presenting a context-correct recovery action:
* - [PermissionStatus.NOT_REQUESTED] / [PermissionStatus.DENIED_CAN_RETRY] — shows a "Grant permission" button that
* re-launches the in-context request.
* - [PermissionStatus.PERMANENTLY_DENIED] — shows an "Open settings" button (user-initiated recovery) because the
* system will no longer show the dialog.
* - [PermissionStatus.GRANTED] — renders nothing.
*
* @param rationale a feature-specific explanation of why the permission is needed.
*/
Tf0883e@Composable
Tff7b72internal Tff7b72fun Td2a8ffPermissionRecoveryCardTb4b4b4(
Te6edf3statusTb4b4b4: Te6edf3PermissionStatusTb4b4b4,
Te6edf3rationaleTb4b4b4: Tffa657StringTb4b4b4,
Te6edf3onRequestTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4,
Te6edf3onOpenSettingsTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4,
Te6edf3modifierTb4b4b4: Te6edf3Modifier Tff7b72= Te6edf3ModifierTb4b4b4,
Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3status Tff7b72=Tff7b72= Te6edf3PermissionStatusTb4b4b4.Te6edf3GRANTEDTb4b4b4) Tff7b72return
Tff7b72if Tb4b4b4(Te6edf3status Tff7b72=Tff7b72= Te6edf3PermissionStatusTb4b4b4.Te6edf3PERMANENTLY_DENIEDTb4b4b4) Tb4b4b4{
Te6edf3RecoveryCardTb4b4b4(
Te6edf3message Tff7b72= Te6edf3rationaleTb4b4b4,
Te6edf3actionLabel Tff7b72= Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3open_settingsTb4b4b4)Tb4b4b4,
Te6edf3onAction Tff7b72= Te6edf3onOpenSettingsTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4,
Te6edf3actionIcon Tff7b72= Te6edf3MeshtasticIconsTb4b4b4.Te6edf3AppSettingsAltTb4b4b4,
Tb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3RecoveryCardTb4b4b4(
Te6edf3message Tff7b72= Te6edf3rationaleTb4b4b4,
Te6edf3actionLabel Tff7b72= Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3grant_permissionTb4b4b4)Tb4b4b4,
Te6edf3onAction Tff7b72= Te6edf3onRequestTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
T8b949e/** Convenience overload that reads the status and actions directly from a [PermissionUiState]. */
Tf0883e@Composable
Tff7b72fun Td2a8ffPermissionRecoveryCardTb4b4b4(Te6edf3stateTb4b4b4: Te6edf3PermissionUiStateTb4b4b4, Te6edf3rationaleTb4b4b4: Tffa657StringTb4b4b4, Te6edf3modifierTb4b4b4: Te6edf3Modifier Tff7b72= Te6edf3ModifierTb4b4b4) Tb4b4b4{
Te6edf3PermissionRecoveryCardTb4b4b4(
Te6edf3status Tff7b72= Te6edf3stateTb4b4b4.Te6edf3statusTb4b4b4,
Te6edf3rationale Tff7b72= Te6edf3rationaleTb4b4b4,
Te6edf3onRequest Tff7b72= Te6edf3stateTb4b4b4.Te6edf3requestTb4b4b4,
Te6edf3onOpenSettings Tff7b72= Te6edf3stateTb4b4b4.Te6edf3openAppSettingsTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.08s